package com.zjw.zy.ext

import android.widget.EditText

/**
 * @author     ：zhong.jw
 * @date       ：Created in 2022/9/30 11:57
 * @description：
 */


/**
 * 常态，不获取键盘，不可编辑
 * */
fun EditText.normal() {
    this.isFocusable = false
    this.isFocusableInTouchMode = false
    this.isCursorVisible = false
}


/**
 * 编辑态，获取键盘
 * */
fun EditText.edit() {
    this.isFocusable = true
    this.isFocusableInTouchMode = true
    this.requestFocus()
    this.isCursorVisible = true

    //光标选择最后
    this.selectLast()
}


/**
 * 编辑态，获取键盘
 * */
fun EditText.selectLast() {
    //光标选择最后
    this.setSelection(text.toString().length)
}

fun EditText.deleteLast() {
    val start = text.toString().length - 1
    if (start >= 0) {
        this.editableText.delete(start, start + 1)
    }
}

fun EditText.value() = this.text.toString()